package captcha

import (
	"fmt"
	"github.com/gin-gonic/gin"
	ca "github.com/steambap/captcha"
	"my_gin_open/model"
	"my_go_open/utils"
	"strings"
	"time"
)

func WriteWithOptions(c *gin.Context, n string, w, h, l uint) {
	data, _ := ca.New(int(w), int(h), func(options *ca.Options) {
		options.TextLength = int(l)
	})
	now := time.Now().Unix()
	sign := fmt.Sprintf("%s%s%d%s", strings.ToLower(data.Text), model.AppKey, now, c.ClientIP())
	value := fmt.Sprintf("time=%d&sign=%s", now, utils.StrMd5(sign))
	c.SetCookie(n, value, 300, "/", "", false, true)
	_ = data.WriteImage(c.Writer)
}
